package com.example.mianshi;

public class SortFileThread implements Runnable{
    private DoWorkTemplate template;

    public SortFileThread(DoWorkTemplate template){
        this.template = template;
    }

    @Override
    public void run() {
        while(true) {
            if (!template.queue.isEmpty()) {
                MFile mFileNew = template.queue.poll();
                MFile mFileOld = template.treeMap.get(mFileNew.getGroupId());
                if (mFileOld == null) {
                    template.treeMap.put(mFileNew.getGroupId(), mFileNew);
                } else {
                    if (mFileOld.getQuota() > mFileNew.getQuota()) {
                        //template.treeMap.remove(mFileOld);
                        template.treeMap.put(mFileNew.getGroupId(), mFileNew);
                    }
                }
            }else {
                if(template.countDownLatch.getCount() <= 1){
                    System.out.println("==========="+template.countDownLatch.getCount());
                    template.countDownLatch.countDown();
                    break;
                }
            }
        }
    }

}
